package com.xian.im.modules.avchat.rule.handler;

import com.xian.im.common.constant.CommandCodeConstant;
import com.xian.im.common.constant.CommandConstant;
import com.xian.im.common.exception.BusinessException;
import com.xian.im.common.model.dto.GroupUserDto;
import com.xian.im.common.model.session.SessionUser;
import com.xian.im.common.proto.MsgRequest;
import com.xian.im.modules.avchat.rule.CheckMute;
import com.xian.im.modules.im.core.IGroupUserCoreService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: xian-code
 * @description: 禁言 Checking
 * @author: liru.xian
 * @create: 2021-01-21 16:38
 **/
@Slf4j
@Component
public class MemberCheckMute implements CheckMute {

    @Autowired
    private IGroupUserCoreService groupUserCoreService;
    /**
     *  是否禁言  member
     * @param message
     * @return
     */
    @Override
    public void mute(MsgRequest message, SessionUser sessionUser){
        log.debug("成员禁言");
        if(message.getCmd().equals(CommandConstant.GROUP_CMD)){
            if(message.getCmdCode().equals(CommandCodeConstant.GROUP_SEND)){
                GroupUserDto userDto = new GroupUserDto();
                userDto.setUserAccount(sessionUser.getAccount());
                userDto.setGroupUniqueId(message.getGroupUniqueId());
                Boolean aBoolean = groupUserCoreService.existMute(userDto);
                if(aBoolean){
                    throw new BusinessException("您已被禁言无法发言");
                }
            }
        }
    }
}
